<!DOCTYPE html>
<html>

<head>
    <title>点赞消息</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="../js/bootstrap/css/bootstrap.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="../js/bootstrap/js/bootstrap.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
    <link rel="stylesheet" href="/css/reset.css" />
    <link rel="stylesheet" href="/css/message.css" />
    <script src="/js/plugins/jquery-form/jquery.form.js"></script>
    <script src="/js/plugins/jrender/jrender.js"></script>

</head>
<script>
        $(function () {
        //获取当前用户id
        //从本地session中取出缓存的对象
        var user = JSON.parse(sessionStorage.getItem("user"));
        //发送get请求查询数据
        $.get("/users/privatemessage",{userId:user.id},function (data) {
            console.log(data);
            //渲染到界面中
            $("#messages").renderValues({list:data},{
                handle:function (ele,value) {
                    $(ele).attr("myId",value);
                },
            });

        });

        //发送私信发送按钮
        $(".transferSubmitBtn").click(function () {
            console.log(user.id);
            $("#transferForm input[name='sendId']").val(user.id);
            $("#transferForm").ajaxSubmit(function (data) {
                window.location.reload();
            });

        });
        //回复发送按钮
        $(".replyBtn").click(function () {
            $("#messageForm").ajaxSubmit(function (data) {
                window.location.reload();
            });

        });
        //弹出模态框发送私信
        $(".save").click(function () {
            $("#transferModal").modal("show");
        });
        //动态绑定事件回复

        $("#messages").on("click","#reply",function () {
            $("#replymsg").modal("show");
            //获取当前私信id
            var id = $(this).attr("myId");
            console.log(id);
            //获取当前的私信的所有信息
            $.get("/privatemessages",{id:id},function (data) {
                $("#replymsg input[name='sendId']").val(user.id);
                $("#replymsg input[name='receiverId']").val(data.sendId);
                $("#replymsg input[name='replyId']").val(id);
            })
        })
    })
</script>
<body>

<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left" ></i></span>
            </a>
        </div>

        <div class="col">
            <span>私信消息</span>
        </div>
        <div class="col">
            <i class="fa fa-pencil-square save" aria-hidden="true"></i>
        </div>
    </div>
</div>
<!--当前系统消息-->
<div id="messages">
<div render-loop="list" >
    <div class="container systemMsg" >
        <dl class="itemList">
            <dd>
                <p>私信消息:</p>
                <img class="rounded-circle head-img" render-src="list.headImgUrl" width="20" style="float:left;">
                <span render-html="list.sendName"></span>
                <span render-html="list.sendtime" ></span><br>
                <p  render-html="list.message"></p>
                <a id="reply"  class="fa fa-pencil-square"  render-key="list.id" render-fun="handle">回复</a>
                <dl render-loop="list.pmg" >
                    <dl style=" border:1px solid #cceff5;background:#fafcfd">
                        <p>我回复:</p>
                        <img class="rounded-circle head-img" render-src="list.headImgUrl" width="20" style="float:left;">
                        <span render-html="list.sendName"></span>
                        <span render-html="list.pmg.sendtime" ></span><br>
                        <p  render-html="list.pmg.message"></p>
                    </dl>
                </dl>
            </dd>

        </dl>

    </div>
</div>
</div>
<!--发送私信模态框-->
<div class="modal fade" id="transferModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">发送私信</h5>
            </div>
            <div class="modal-body">
                <!--填充编辑界面-->
                <form class="form-horizontal" action="/privatemessages/save" method="post" id="transferForm">
                    <input type="hidden" name="sendId" /> <!--发件人id-->

                    <div class="form-group">
                        <label  class="col-lg-4 control-label">收件人：</label>
                        <div class="col-lg-6">
                            <select class="form-control" id=" " name="receiverId">
                                <option value="1">逍遥</option>
                                <option value="2">歪果仁</option>
                                <option value="3">巴尔</option>
                                <option value="4">匿名</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="reason" class="col-lg-4 control-label">私信内容：</label>
                        <div class="col-lg-6">
                            <textarea type="text" class="form-control" id="reason" name="message" cols="10"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary transferSubmitBtn">发送</button>
            </div>
        </div>
    </div>
</div>


<div class="modal fade" id="replymsg" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">回复私信</h5>
            </div>
            <div class="modal-body">
                <!--填充编辑界面-->
                <form class="form-horizontal" action="/privatemessages/save" method="post" id="messageForm">
                    <input type="hidden" name="sendId" /> <!--发件人id-->
                    <input type="hidden" name="receiverId" /> <!--接收人id-->
                    <input type="hidden" name="replyId" /> <!--是那条回复-->
                    <div class="form-group">
                        <label for="reason" class="col-lg-4 control-label">回复内容：</label>
                        <div class="col-lg-6">
                            <textarea type="text" class="form-control" id="message" name="message" cols="10"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary replyBtn">回复</button>
            </div>
        </div>
    </div>
</div>
</body>

</html>